/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package proyecto3;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 *
 * @author Lucia
 */
public class VentanaAplicacion extends JFrame{

    public VentanaAplicacion(String titulo) {
        super(titulo);
        configuracionInicial();
        setResizable(true);
        ajustarComponentes(getContentPane());
        ajustarMenus();
        ajustarEventos();
        
    }
    
     private void configuracionInicial(){
            setSize(900, 600);
        setLocationRelativeTo(null);
        
      setMinimumSize(getSize());
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        
    }
     private void ajustarComponentes(Container c) {
           // c.setLayout(new BorderLayout());
           c.add(BorderLayout.CENTER, panel = new JPanel() {
              
            @Override
            public void paintComponent(Graphics bg) {
                super.paintComponent(bg);
                Graphics2D g = (Graphics2D) bg;

                Dimension tamano = getSize();
                ImageIcon imagenFondo = new ImageIcon(getClass().getResource("imagen/bus1.png"));

                g.drawImage(imagenFondo.getImage(), 0, 0, tamano.width, tamano.height, null);
                setOpaque(false);
                
               
                
                
                
            }
           });
           
        panel.setLayout(new GridBagLayout());
      
        GridBagConstraints x = new GridBagConstraints();
        x.insets = new Insets(2, 2, 2, 2);
        
         //BOTON COMPRAR TIQUETE
        x.gridx = 1;
        x.gridy = 0;
        x.fill = GridBagConstraints.NONE;
        btnTiquete = new JButton("Comprar Tiquetes");
        btnTiquete.setBackground(Color.CYAN.darker());
        panel.add(btnTiquete,x);
        
        //MENU DE AGREGAR
        x.gridx = 0;
        x.gridy = 1;
        x.fill = GridBagConstraints.NONE;
       comboAgregar=new JComboBox(menuAgregar);
        panel.add(comboAgregar,x);
        
        //MENU DE ELIMINAR
        x.gridx = 1;
        x.gridy = 1;
        x.fill = GridBagConstraints.NONE;
        comboEliminar = new JComboBox(menuEliminar);
        panel.add(comboEliminar,x);
        
        //MENU DE MODIFICAR
        x.gridx = 2;
        x.gridy = 1;
        x.fill = GridBagConstraints.NONE;
        comboModificar = new JComboBox(menuModificar);       
        panel.add(comboModificar,x);
        
       
        // boton HACER CAMBIOS
        x.gridx = 1;
        x.gridy = 2;
        x.fill = GridBagConstraints.HORIZONTAL;
        btnCambios = new JButton("Iniciar partida");
        btnCambios.setBackground(Color.CYAN.darker());
        panel.add(btnCambios, x);
        
        validarDatos();
           
        // comboAgregar.setBounds(10,10,80,20);
       // comboAgregar.addItem(menuAgregar);
//        comboAgregar.addItem("Carrera");
//        comboAgregar.addIt9em("Bus");

     }
     
     public void validarDatos(){
     btnCambios.addActionListener((ActionEvent ae) -> {
            obtenerDatos();
        });
     
         
         
     
     }
     public boolean obtenerDatos(){
         if(comboAgregar.getSelectedItem() != "Agregar" && comboEliminar.getSelectedItem() != "Eliminar"){
            comboAgregar.setSelectedIndex(0);
            JOptionPane.showMessageDialog(null, "Debe elegir solo un opción a la vez ", "Error!", JOptionPane.ERROR_MESSAGE);
            return false;
         }
         if(comboAgregar.getSelectedItem() != "Agregar" && comboModificar.getSelectedItem() != "Modificar"){
            comboAgregar.setSelectedIndex(0);
            JOptionPane.showMessageDialog(null, "Debe elegir solo un opción a la vez ", "Error!", JOptionPane.ERROR_MESSAGE);
            return false;
         }
         if(comboModificar.getSelectedItem() != "Modificar" && comboEliminar.getSelectedItem() != "Eliminar"){
            comboAgregar.setSelectedIndex(0);
            JOptionPane.showMessageDialog(null, "Debe elegir solo un opción a la vez ", "Error!", JOptionPane.ERROR_MESSAGE);
            return false;
         }
         
         if(comboAgregar.getSelectedItem() == "Agregar"){
             
            
         }
         if(comboModificar.getSelectedItem() != "Modificar"){
         
             
         }
         if(comboEliminar.getSelectedItem() != "Eliminar"){
         
             
         }
         
         
         
     return true;
     }
     
        private void ajustarMenus() {
        menuPrincipal = new JMenuBar();

        menuArchivo = new JMenu("Archivo");
        itemSalir = new JMenuItem("Salir");
        menuArchivo.add(itemSalir);
        menuPrincipal.add(menuArchivo);

        menuAyuda = new JMenu("Ayuda");
        itemAcercaDe = new JMenuItem("Acerca de...");
        menuAyuda.add(itemAcercaDe);
        menuPrincipal.add(menuAyuda);

        setJMenuBar(menuPrincipal);
    }
         private void ajustarEventos() {
        
        itemSalir.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                cerrarAplicacion();
            }
        });

        itemAcercaDe.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                mostrarAcercaDe();
            }
        });
        
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                cerrarAplicacion();
            }
        });
    }
         
          private void cerrarAplicacion(){
        int opt = JOptionPane.showConfirmDialog(this, 
                "¿Desea cerrar la aplicación?","Cerrar Aplicacion", 
                JOptionPane.YES_NO_OPTION);
        if(opt == JOptionPane.YES_OPTION){
            System.exit(0);
        }
    }
    
    public void mostrarAcercaDe() {
        JOptionPane.showMessageDialog(null,INFO_ACERCADE,
            String.format("Acerca de %s..", DESCRIPCION_APLICACION),
            JOptionPane.INFORMATION_MESSAGE);
    }
        
    public void init(){
        setVisible(true);
    }
        
    
    private JPanel panel;
    private JComboBox comboAgregar;
    private JComboBox comboModificar;
    private JComboBox comboEliminar;
    private String[] menuAgregar = {"Agregar", "Carrera", "Bus"};
    private String[] menuModificar = {"Modificar", "Carrera", "Bus"};
    private String[] menuEliminar = {"Eliminar", "Carrera", "Bus"};
     
    private JMenuBar menuPrincipal;
    private JMenu menuArchivo;
    private JMenuItem itemSalir;
    private JMenu menuAyuda;
    private JMenuItem itemAcercaDe;
    
    private JButton btnTiquete;
    private JButton btnCambios;
    
     Color colora=new Color(255,255,255);
     private static final Color nuevoColor = new Color(162, 208, 255);
    
    private static final String INFO_ACERCADE = "\u00A92014 Programación 3\nUniversidad Nacional UNA";
    public static final String DESCRIPCION_APLICACION = "Proyecto#3"; 
    
    
    
}
